#include "Heart.h"
#include <QPainter>
#include <QTimerEvent>
#include <cmath>
#include <QPainterPath>
Heart::Heart(QWidget *parent)
    : QWidget{parent}, m_x(0), m_y(0), m_t(0), m_k(10)
{
    setFixedSize(10, 10); // 设置一个固定的大小，适应爱心绘制
    startTimer(16); // 每16毫秒更新一次
}

void Heart::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.setPen(Qt::red);
    painter.drawPoint(m_x, m_y);
}

void Heart::timerEvent(QTimerEvent *)
{
    if (m_t > 1000)
    {
        update();
        m_t = 0;
    }
    m_x = 16 * m_k * sin(m_k*m_t)*sin(m_k*m_t)*sin(m_k*m_t);
    m_y = 13 * m_k * cos(m_k*m_t) - 5 * m_k * cos(2 * m_k * m_t) - 2 * m_k * cos(3 * m_k * m_t) - cos(4 * m_k * m_t);
    m_x += this->width() / 2;
    m_y -= this->height() / 2;
    m_y *= -1;
    update(m_x,m_y,1,1);
    m_t += 0.1;
}
